import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { useNavigate, Router } from 'react-router-dom';
import { setupAuthInterceptor, setupResponseInterceptor } from './utils/api';

// 设置API认证拦截器，自动在请求头中添加token
setupAuthInterceptor();

// 创建一个模拟的navigate函数用于响应拦截器
const mockNavigate = (path) => {
  window.location.href = path;
};

// 设置API响应拦截器，处理401未授权错误
setupResponseInterceptor(mockNavigate);

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
